package com.hysoft.cxf.ws.utils;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import com.hysoft.cxf.po.Cat;
import com.hysoft.cxf.ws.utils.StringCat.Entry;

public class HyXmlAdapter extends XmlAdapter<StringCat, Map<String,Cat>>{

	@Override
	public StringCat marshal(Map<String, Cat> v) throws Exception {
		StringCat stringCat = new StringCat();
		for (String key : v.keySet()) {
			stringCat.getEntries().add(new Entry(key,v.get(key)));
		}
		return stringCat;
	}

	@Override
	public Map<String, Cat> unmarshal(StringCat v) throws Exception {
		Map<String, Cat> map = new HashMap<String, Cat>();
		for (Entry entry : v.getEntries()) {
			map.put(entry.getKey(),entry.getValue());
		}
		return map;
	}

}
